package com.example.myapplication.slice;

import com.example.myapplication.slice.slice.ProviderTabPageSliderProviderSlice;
import ohos.aafwk.ability.Ability;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.*;

import java.util.List;
import java.util.concurrent.CountedCompleter;

public class ProviderTabPageSliderProvider extends PageSliderProvider {

    private List<Integer> layoutFileIds;
    private AbilitySlice abilitySlice;

    public ProviderTabPageSliderProvider(List<Integer> layoutFileIds,AbilitySlice abilitySlice){
        this.layoutFileIds = layoutFileIds;
        this.abilitySlice = abilitySlice;
    }


    @Override
    public int getCount() {
        return layoutFileIds.size();
    }

    @Override
    public Object createPageInContainer(ComponentContainer componentContainer, int i) {
        Integer id = layoutFileIds.get(i);
        Component component= LayoutScatter.getInstance(abilitySlice).parse(id, null, false);
        componentContainer.addComponent(component);
        return component;
    }

    @Override
    public void destroyPageFromContainer(ComponentContainer componentContainer, int i, Object o) {
        componentContainer.removeComponent((Component) o);

    }

    @Override
    public boolean isPageMatchToObject(Component component, Object o) {
        return true;
    }
}
